import React, { useState, useEffect } from 'react'
import { useNavigate } from 'react-router-dom'
import { Toast, NavBar, Button } from 'react-vant';
import '../../scss/lwl/question.css'
import axios from 'axios'
import { replace, filtion } from "verification-sensitive";
export default function Question() {
  const jump = useNavigate()
  const [question, setQuestion] = useState('')
  const submit = async () => {
    if (question == '') {
      Toast.fail('请输入内容')
    } else {
      let flag = filtion(question)
      if (flag == true) {
        await axios.post('http://localhost:3000/questionAdd', { question: replace(question, '*') })
        Toast.info('添加成功')
        setQuestion('')
        jump('/')
      }else{
        await axios.post('http://localhost:3000/questionAdd', { question: question })
        Toast.info('添加成功')
        setQuestion('')
        jump('/')
      }
    }
  }
  return (
    <div id='question'>
      <NavBar
        title="提问"
        onClickLeft={() => { jump(-1) }}
      />
      <h2 style={{ paddingLeft: '10px' }}>福港园大厦</h2>
      <div className="questionText">
        <textarea placeholder='请描述你的问题' value={question} onChange={(e) => { setQuestion(e.target.value) }}></textarea>
      </div>
      <h3 style={{ paddingLeft: '10px' }}>你还可以</h3>

      <div className="YouAnd">
        <button onClick={(e) => { setQuestion(e.target.innerText) }}>小区和周围几个小区相比，有什么优缺点？</button>
        <button onClick={(e) => { setQuestion(e.target.innerText) }}>小区现在价格算高还是低？现在买房合适吗？</button>
        <button onClick={(e) => { setQuestion(e.target.innerText) }}>想买来给爸妈住，环境适合老年人吗？</button>
        <button onClick={(e) => { setQuestion(e.target.innerText) }}>小区一居室最近成交价是多少？</button>
      </div>
      <div className="submit">
        <Button type='warning' onClick={() => { submit() }}>提交</Button>
      </div>
    </div>
  )
}
